package com.ha8.netease.views.components
{
	import com.ha8.netease.AppFacade;
	import com.ha8.netease.PrivateNotify;
	import com.ha8.netease.PublicNotify;
	
	import flash.events.MouseEvent;
	import flash.net.sendToURL;
	
	import mx.controls.Label;
	
	import spark.components.Button;
	import spark.components.supportClasses.SkinnableComponent;
	
	public class PushBar extends SkinnableComponent
	{
		public function PushBar()
		{
			super();
		}
		
		//--------------------------------------------------------------------------
		//
		//  SkinPart
		//
		//--------------------------------------------------------------------------
		
		[SkinPart(required='true')]
		public var backBtn:IconButton;
		
		[SkinPart(required='true')]
		public var homeBtn:IconButton;
		
		[SkinPart(required='true')]
		public var titleText:Label;
		
		//--------------------------------------------------------------------------
		//
		//  Variables
		//
		//--------------------------------------------------------------------------
		
		private var _title:String;

		public function get title():String
		{
			return _title;
		}

		public function set title(value:String):void
		{
			_title = value;
			
			if (titleText)
				titleText.text = _title;
		}

		//--------------------------------------------------------------------------
		//
		//  Overridden Methods
		//
		//--------------------------------------------------------------------------
		
		override protected function partAdded(partName:String, instance:Object):void
		{
			super.partAdded(partName, instance);
			if (instance == titleText)
			{
				titleText.text = title;
			}
			else if (instance == backBtn)
			{
				backBtn.addEventListener(MouseEvent.CLICK, backBtn_clickHandler, false, 0, true);
			}
			else if (instance == homeBtn)
			{
				homeBtn.addEventListener(MouseEvent.CLICK, homeBtn_clickHandler, false, 0, true);
			}
		}
		
		override protected function partRemoved(partName:String, instance:Object):void
		{
			super.partRemoved(partName, instance);
		}
		
		//--------------------------------------------------------------------------
		//
		//  Event Handlers
		//
		//--------------------------------------------------------------------------
		
		private function backBtn_clickHandler(e:MouseEvent):void
		{
			AppFacade.getInstance().sendNotification(PrivateNotify.DISPLAY_PRE_PAGE);
		}
		
		private function homeBtn_clickHandler(e:MouseEvent):void
		{
			AppFacade.getInstance().sendNotification(PublicNotify.DISPLAY_HOME_PAGE);
		}
		
	}
}